﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ArduinoSharp.Lib
{
    public class ArduinoSerialData
    {
        private string _Name;
        private int[] _Data;

        public bool HasValue;
        public string Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                this._Name = value;
            }
        }

        public int[] Data
        {
            set
            {
                this._Data = value;
            }
            get
            {
                return this._Data;
            }
        }
        public ArduinoSerialData()
        {
            this.HasValue = false;
        }
        public ArduinoSerialData(string str)
        {
            try
            {
                var splited = str.Split(ArduinoCommand.CommandDelimiter)[0].Split(ArduinoCommand.FieldDelimiter);
                if (int.Parse(splited[0]) == ArduinoCommand.CommandsPrefixes.ADC_DATA) this.Name = "ADC_DATA";
                this.Data = new int [8];
                for (int i = 0 ; i < 8; i++)
                {
                    this.Data[i] = int.Parse(splited[i+1]);
                }
                this.HasValue = true;
                //JObject jObject = JObject.Parse(jsonStr);

                //this._Name = jObject["Name"].Value<string>();
                //this._Data = jObject["Data"].Values<int>().ToArray();
                //this.HasValue = true;
            }
            catch (Exception)
            {
                this.HasValue = false;
            }
           
        }
    }



}
